#!/usr/bin/env python
# -*- coding: UTF-8 -*-

from oriolus.pith.packets.packet import FullName

class Catalogue:
    def __init__(self, trotter):
        self.__trotter = trotter

    def identify_packets(self, names):
        """Identify packets by name using Trotter's packet list

        @param names: a list of packet-names e.g. ("packetname", "packetname-1.0.1.2")
        @return: a list of FullName objects
        """

        full_names = []
        trotter_list = self.__trotter.get_packet_list()

        for name in names:
            for full_name in trotter_list:
                if full_name.startswith(name):
                    if not full_name in full_names:
                        full_names.append(full_name)

        return [FullName.parse(full_name) for full_name in full_names]